<template>
	<view>
		<view v-for="(item,index) in conversationList.list" :key="index">
			<uni-list-chat @click="showT(data.content,item,index)" clickable :avatar-circle="true"
				:title="item.unickname" :avatar="item.avatar" :note="str" :time="str"></uni-list-chat>
		</view>
	</view>
</template>

<script>
	import {
		mapState, //先导入mapState方法
		mapMutations,
		mapActions,
		mapGetters,
	} from "vuex";
	export default {
		data() {
			return {
				str: '',
				data: null,
				uid: uni.getStorageSync("ID"),
				conversationList: [],
				message: {},
				messagetype: null,
				isGroup: false,
			};
		},
		onLoad(options) {
			if (options.data) {
				let json = JSON.parse(options.data)
				this.data = json
				console.log(options.messagetype, ' options.messagetype');
				this.messagetype = options.messagetype
			}
		},
		onShow() {
			this.getFriend()
		},
		methods: {
			...mapMutations("m_message", [
				"saveMessageStorage",
				"changeConversationList",
				"DELETE_MessageOne"
			]),
			async getFriend() {
				this.conversationList = await this.$API.friendApi.friendList();
				console.log(this.conversationList, 'conversationList');
			},
			showT(content, item, index) {
				console.log(content, '几次');
				uni.showModal({
					title: `发送给${item.unickname}`,
					content: content,
					success: (res) => {
						console.log();
						if (res.confirm) {
							//转发单聊
							if (!this.isGroup) {
								this.message.messageId = this.$uuid();

								this.message.fromId = this.uid

								this.message.toId = item.userid;

								this.message.createTime = new Date();
								
								this.message.messagetype = "0"

								/* 类型 */
								this.message.type = this.messagetype
								// /* 内容 */
								this.message.content = content

								this.message.avatar = this.userAvatar

								this.message.uemployeeid = false

								this.message.readStatus = 0

								this.message.unickname = uni.getStorageSync("userInfo").unickname
							} else {
								/* 类型 */
								this.message.type = this.messagetype
								/* 内容 */
								this.message.content = content

								this.message.fromId = uni.getStorageSync("ID");

								this.message.createTime = new Date();

								this.message.groupName = this.form.xtGroupName;

								this.message.groupAvatar = this.form.groupAvatar;

								this.message.messageId = this.$uuid();
								
								this.message.messagetype = "1"

								this.message.unickname = uni.getStorageSync('userInfo').unickname

								this.message.groupId = this.form.teamId

								this.message.avatar = uni.getStorageSync('userInfo').avatar
							}

							let msg = {
								code: "2",
								message: this.message,
							};

							this.$ws.send(JSON.stringify(msg));
							uni.showToast({
								title: '已转发',
								complete() {
									uni.navigateBack()
								}
							})
							/* 判断是是否是群聊 因为群聊会自动推到消息表 所以不用收到添加hfghf
							 */
							if (this.isGroup) {
								return;
							}

							let newdata = {
								"friendId": item.userid,
								"message": {
									...msg.message
								},
							};

							this.saveMessageStorage(newdata)

						

						} else if (res.cancel) {
							console.log('用户点击取消');
						}
					}
				});
			}
		},
		computed: {},
	}
</script>

<style lang="scss">

</style>